#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

string alfavit(string word) {
    unordered_map<string, string> words = {
        {"zero", "0"},
        {"one", "1"},
        {"two", "2"},
        {"three", "3"},
        {"four", "4"},
        {"five", "5"},
        {"six", "6"},
        {"seven", "7"},
        {"eight", "8"},
        {"nine", "9"}
    };
    return words[word];
}

bool pr(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i*i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    string input;
    cin >> input;
    vector<string> input_words;
    string word;
    for (char c : input) {
        if (c == ' ') {
            input_words.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    input_words.push_back(word);

    if (input_words.size() != 3) {
        cout << "Wrong input" << endl;
    } else {
        string number_str = "";
        for (string word : input_words) {
            number_str += alfavit(word);
        }
        if (! all_of(number_str.begin(), number_str.end(), ::isdigit) || number_str.size() != 3) {
            cout << "Wrong input" << endl;
        } else {
            int number = stoi(number_str);
            int l = -1;
            int u = -1;
            int i = 1;
            while (true) {
                if (number - i >= 0 && pr(number - i)) {
                    l = number - i;
                    break;
                }
                if (pr(number + i)) {
                    u = number + i;
                    break;
                }
                i++;
            }
            if (l != -1) {
                cout << l << endl;
            } else if (u != -1) {
                cout << u << endl;
            }
        }
    }

    return 0;
}
